package com.reg;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017-05-31.
 */
public class BracketRegular implements IRegular {

    ArrayList<IRegular> regulars = new ArrayList<>();

    public BracketRegular(ArrayList bracket){
        regulars.addAll(bracket);
    }

    public BracketRegular addRegular(IRegular regular){
        regulars.add(regular);
        return this;
    }


    @Override
    public List<String> match(char[] chars) {
        ArrayList<String> strings = new ArrayList<>();
        for(int i = 0 ;i < regulars.size(); i++){
            List<String> matched = regulars.get(i).match(chars);
            if(matched!=null) {
                strings.addAll(matched);
            }
        }
        return strings;
    }
}
